import argparse

# action='acount' 可选参数的传值方式 -v -vv -vvv...

parser = argparse.ArgumentParser()
parser.add_argument('square', type=int,
                    help='display a square of a given number')

# 如果没有default=0
# verbosity默认为None
# action='count'  计算v出现的个数 如: -v 1次 -vv两次
parser.add_argument("-v", "--verbosity", default=0,
                    action="count", help="increase output verbosity")
args = parser.parse_args()
answer = args.square**2

# python argparse5.py 32
# python argparse5.py 32 -v
# python argparse5.py 32 -vv
if args.verbosity == 2:
    print('The square of {} equals {}'.format(args.square, answer))
elif args.verbosity == 1:
    print('{}^2 == {}'.format(args.square, answer))
else:
    print(answer)

# type, action, default, help, choices
